<?php
/*
 Gets the html table to manage users.
 */
function get_users_manage_table($users, $controller) {
	$CI = &get_instance();
	$table = '<table class="table table-striped table-bordered table-hover" id="dataTables-example">';

	$headers = array('#', $CI -> lang -> line('header_table_username'), $CI -> lang -> line('header_table_email'),
	//$CI->lang->line('header_table_phone'),
	$CI -> lang -> line('header_table_created_date'), $CI -> lang -> line('header_table_status'), $CI -> lang -> line('header_table_action'));

	$table .= '<thead><tr>';
	foreach ($headers as $header) {
		$table .= "<th>$header</th>";
	}
	$table .= '</tr></thead><tbody>';
	$table .= get_users_manage_table_data_rows($users, $controller);
	$table .= '</tbody></table>';
	return $table;
}

/*
 Gets the html data rows for the user.
 */
function get_users_manage_table_data_rows($users, $controller) {
	$CI = &get_instance();
	$table_data_rows = '';

	foreach ($users->result() as $person) {
		$table_data_rows .= get_user_data_row($person, $controller);
	}

	if ($users -> num_rows() == 0) {
		$table_data_rows .= "<tr><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td></tr>";
	}

	return $table_data_rows;
}

function get_user_data_row($person, $controller) {
	$CI = &get_instance();
	$controller_name = strtolower(get_class($CI));
	$is_active = ($person -> status == '1') ? 'Enabled' : 'Disabled';
	$table_data_row = '<tr>';
	$table_data_row .= "<td>" . $person -> user_id . "</td>";
	$table_data_row .= '<td>' . character_limiter($person -> username, 13) . '</td>';
	$table_data_row .= '<td>' . mailto($person -> email, character_limiter($person -> email, 22)) . '</td>';
	//$table_data_row.='<td>'.character_limiter($person->phone,22).'</td>';
	$table_data_row .= '<td>' . $person -> created_date . '</td>';
	$table_data_row .= '<td>' . $is_active . '</td>';

	$table_data_row .= '<td><center><a href="' . base_url() . str_replace('_', '-', $controller_name) . '/update-user/' . $person -> user_id . '" title="' . $CI -> lang -> line('common_edit') . '"><i class="fa fa-edit fa-fw fa-lg"></i></a> | <a href="' . base_url() . str_replace('_', '-', $controller_name) . '/delete-user/' . $person -> user_id . '" title="' . $CI -> lang -> line('common_delete') . '" onclick="return confirm(\'Are you sure want to delete?\');"><i class="fa fa-trash-o fa-fw fa-lg"></i></a>| <a href="' . base_url() . 'manage-user-permissions/user-modules/' . $person -> user_id . '" title="Permissions"><i class="fa fa-th fa-fw fa-lg"></i></a></center></td>';

	$table_data_row .= '</tr>';

	return $table_data_row;
}


/*
 Gets the html table to manage products owners.
 */
function get_product_owners_manage_table($product_owners, $controller) {
	$CI = &get_instance();
	$table = '<table class="table table-striped table-bordered table-hover" id="dataTables-example">';

	$headers = array('#', $CI -> lang -> line('header_table_username'), $CI -> lang -> line('header_table_email'),
	//$CI->lang->line('header_table_phone'),
	$CI -> lang -> line('header_table_created_date'), $CI -> lang -> line('header_table_status'), $CI -> lang -> line('header_table_action'));

	$table .= '<thead><tr>';
	foreach ($headers as $header) {
		$table .= "<th>$header</th>";
	}
	$table .= '</tr></thead><tbody>';
	$table .= get_product_owner_manage_table_data_rows($product_owners, $controller);
	$table .= '</tbody></table>';
	return $table;
}

/*
 Gets the html data rows for the user.
 */
function get_product_owner_manage_table_data_rows($product_owners, $controller) {
	$CI = &get_instance();
	$table_data_rows = '';

	foreach ($product_owners->result() as $product_owner) {
		$table_data_rows .= get_product_owner_data_row($product_owner, $controller);
	}

	if ($product_owners -> num_rows() == 0) {
		$table_data_rows .= "<tr><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td></tr>";
	}

	return $table_data_rows;
}

function get_product_owner_data_row($product_owner, $controller) {
	$CI = &get_instance();
	$controller_name = strtolower(get_class($CI));
	$is_active = ($product_owner -> status == '1') ? 'Enabled' : 'Disabled';
	$table_data_row = '<tr>';
	$table_data_row .= "<td>" . $product_owner -> product_owner_id . "</td>";
	$table_data_row .= '<td>' . character_limiter($product_owner -> username, 13) . '</td>';
	$table_data_row .= '<td>' . mailto($product_owner -> email, character_limiter($product_owner -> email, 35)) . '</td>';
	//$table_data_row.='<td>'.character_limiter($person->phone,22).'</td>';
	$table_data_row .= '<td>' . $product_owner -> created_date . '</td>';
	$table_data_row .= '<td>' . $is_active . '</td>';

	$table_data_row .= '<td><center><a href="' . base_url() . str_replace('_', '-', $controller_name) . '/update-product-owner/' . $product_owner -> product_owner_id . '" title="' . $CI -> lang -> line('common_edit') . '"><i class="fa fa-edit fa-fw fa-lg"></i></a> | <a href="' . base_url() . str_replace('_', '-', $controller_name) . '/delete-product-owner/' . $product_owner -> product_owner_id . '" title="' . $CI -> lang -> line('common_delete') . '" onclick="return confirm(\'Are you sure want to delete?\');"><i class="fa fa-trash-o fa-fw fa-lg"></i></a>| <a href="' . base_url() . 'manage-product-owners/list-owner-products/' . $product_owner -> product_owner_id . '" title="List all owner products"><i class="fa fa-th fa-fw fa-lg"></i></a></center></td>';

	$table_data_row .= '</tr>';

	return $table_data_row;
}



/*
 Gets the html table to manage user products .
 */
function get_user_products_manage_table($user_products, $controller) {
	$CI = &get_instance();
	$table = '<table class="table table-striped table-bordered table-hover" id="dataTables-example">';

	$headers = array('#', "Owner ","Product Name","Price","Picture",
	//$CI->lang->line('header_table_phone'),
	$CI -> lang -> line('header_table_created_date'), $CI -> lang -> line('header_table_status'), $CI -> lang -> line('header_table_action'));

	$table .= '<thead><tr>';
	foreach ($headers as $header) {
		$table .= "<th>$header</th>";
	}
	$table .= '</tr></thead><tbody>';
	$table .= get_user_products_manage_table_data_rows($user_products, $controller);
	$table .= '</tbody></table>';
	return $table;
}

/*
 Gets the html data rows for the user.
 */
function get_user_products_manage_table_data_rows($user_products, $controller) {
	$CI = &get_instance();
	$table_data_rows = '';

	foreach ($user_products->result() as $user_product) {
		$table_data_rows .= get_user_product_data_row($user_product, $controller);
	}

	if ($user_products -> num_rows() == 0) {
		$table_data_rows .= "<tr><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td></tr>";
	}

	return $table_data_rows;
}

function get_user_product_data_row($user_product, $controller) {
	$CI = &get_instance();
	$controller_name = strtolower(get_class($CI));
	$is_active = ($user_product -> status == '1') ? 'Enabled' : 'Disabled';
	$table_data_row = '<tr align="center">';
	$table_data_row .= "<td>" . $user_product -> product_id . "</td>";
	$table_data_row .= "<td>" . $user_product -> username . "</td>";
	$table_data_row .= '<td>' . character_limiter($user_product -> product_name, 13) . '</td>';
	$table_data_row .= '<td>' . character_limiter($user_product -> price, 13) . '</td>';
	$table_data_row .= '<td><img src="'.base_url().F_IMG.$user_product->image_name.'"class="img-circle" width="160"/></td>';
	//$table_data_row.='<td>'.character_limiter($person->phone,22).'</td>';
	$table_data_row .= '<td>' . $user_product -> created_date . '</td>';
	$table_data_row .= '<td>' . $is_active . '</td>';

	$table_data_row .= '<td><center><a href="' . base_url() . str_replace('_', '-', $controller_name) . '/delete-user-product/' . $user_product -> product_id . '" title="' . $CI -> lang -> line('common_delete') . '" onclick="return confirm(\'Are you sure want to delete?\');"><i class="fa fa-trash-o fa-fw fa-lg"></i></a></center></td>';

	$table_data_row .= '</tr>';

	return $table_data_row;
}



/*
 Gets the html table to manage list product owners .
 */
function get_list_product_owners_manage_table($user_products, $controller) {
	$CI = &get_instance();
	$table = '<table class="table table-striped table-bordered table-hover" id="dataTables-example">';

	$headers = array('#', "Product Name","Price","Picture",
	//$CI->lang->line('header_table_phone'),
	$CI -> lang -> line('header_table_created_date'), $CI -> lang -> line('header_table_status'), $CI -> lang -> line('header_table_action'));

	$table .= '<thead><tr>';
	foreach ($headers as $header) {
		$table .= "<th>$header</th>";
	}
	$table .= '</tr></thead><tbody>';
	$table .= get_list_products_owner_manage_table_data_rows($user_products, $controller);
	$table .= '</tbody></table>';
	return $table;
}

/*
 Gets the html data rows for the user.
 */
function get_list_products_owner_manage_table_data_rows($user_products, $controller) {
	$CI = &get_instance();
	$table_data_rows = '';

	foreach ($user_products->result() as $user_product) {
		$table_data_rows .= get_list_product_owner_data_row($user_product, $controller);
	}

	if ($user_products -> num_rows() == 0) {
		$table_data_rows .= "<tr><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td></tr>";
	}

	return $table_data_rows;
}

function get_list_product_owner_data_row($user_product, $controller) {
	$CI = &get_instance();
	$controller_name = strtolower(get_class($CI));
	$is_active = ($user_product -> status == '1') ? 'Enabled' : 'Disabled';
	$table_data_row = '<tr align="center">';
	$table_data_row .= "<td>" . $user_product -> product_id . "</td>";
	//$table_data_row .= "<td>" . $user_product -> username . "</td>";
	$table_data_row .= '<td>' . character_limiter($user_product -> product_name, 13) . '</td>';
	$table_data_row .= '<td>' . character_limiter($user_product -> price, 13) . '</td>';
	$table_data_row .= '<td><img src="'.base_url().F_IMG.$user_product->image_name.'"class="img-circle" width="160"/></td>';
	//$table_data_row.='<td>'.character_limiter($person->phone,22).'</td>';
	$table_data_row .= '<td>' . $user_product -> created_date . '</td>';
	$table_data_row .= '<td>' . $is_active . '</td>';

	$table_data_row .= '<td><center><a href="' . base_url() . str_replace('_', '-', $controller_name) . '/delete-owner-product/' . $user_product -> product_id . '" title="' . $CI -> lang -> line('common_delete') . '" onclick="return confirm(\'Are you sure want to delete?\');"><i class="fa fa-trash-o fa-fw fa-lg"></i></a></center></td>';

	$table_data_row .= '</tr>';

	return $table_data_row;
}



/*
 Gets the html table to manage users group.
 */
function get_user_group_manage_table($users, $controller) {
	$CI = &get_instance();
	$table = '<table class="table table-striped table-bordered table-hover" id="dataTables-example">';

	$headers = array('#', $CI -> lang -> line('header_table_username'),
	//$CI->lang->line('header_table_email'),
	//$CI->lang->line('header_table_phone'),
	$CI -> lang -> line('header_table_created_date'), $CI -> lang -> line('header_table_status'), $CI -> lang -> line('header_table_action'));

	$table .= '<thead><tr>';
	foreach ($headers as $header) {
		$table .= "<th>$header</th>";
	}
	$table .= '</tr></thead><tbody>';
	$table .= get_user_group_manage_table_data_rows($users, $controller);
	$table .= '</tbody></table>';
	return $table;
}

/*
 Gets the html data rows for the user.
 */
function get_user_group_manage_table_data_rows($users, $controller) {
	$CI = &get_instance();
	$table_data_rows = '';

	foreach ($users->result() as $person) {
		$table_data_rows .= get_user_group_data_row($person, $controller);
	}

	if ($users -> num_rows() == 0) {
		$table_data_rows .= "<tr><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td></tr>";
	}

	return $table_data_rows;
}

function get_user_group_data_row($person, $controller) {
	$CI = &get_instance();
	$controller_name = strtolower(get_class($CI));
	$is_active = ($person -> status == '1') ? 'Enabled' : 'Disabled';
	$table_data_row = '<tr>';
	$table_data_row .= "<td>" . $person -> user_group_id . "</td>";
	$table_data_row .= '<td>' . character_limiter($person -> name, 13) . '</td>';
	//$table_data_row.='<td>'.mailto($person->email,character_limiter($person->email,22)).'</td>';
	//$table_data_row.='<td>'.character_limiter($person->phone,22).'</td>';
	$table_data_row .= '<td>' . $person -> created_date . '</td>';
	$table_data_row .= '<td>' . $is_active . '</td>';

	$table_data_row .= '<td><center><a href="' . base_url() . str_replace('_', '-', $controller_name) . '/update-user-permission/' . $person -> user_group_id . '" title="' . $CI -> lang -> line('common_edit') . '"><i class="fa fa-edit fa-fw fa-lg"></i></a> | <a href="' . base_url() . str_replace('_', '-', $controller_name) . '/delete-user-permission/' . $person -> user_group_id . '" title="' . $CI -> lang -> line('common_delete') . '" onclick="return confirm(\'Are you sure want to delete?\');"><i class="fa fa-trash-o fa-fw fa-lg"></i></a></center></td>';

	$table_data_row .= '</tr>';

	return $table_data_row;
}

/*
 Gets the html table to manage tags.
 */
function get_slide_promotion_manage_table($slides, $controller) {
	$CI = &get_instance();
	$table = '<table class="table table-striped table-bordered table-hover" id="dataTables-example">';

	$headers = array('#', "Title",

	//$CI->lang->line('header_table_phone'),
	"Image", "Created Date",$CI -> lang -> line('header_table_status'), $CI -> lang -> line('header_table_action'));

	$table .= '<thead><tr>';
	foreach ($headers as $header) {
		$table .= "<th>$header</th>";
	}
	$table .= '</tr></thead><tbody>';
	$table .= get_slide_promotion_manage_table_data_rows($slides, $controller);
	$table .= '</tbody></table>';
	return $table;
}

/*
 Gets the html data rows for the user.
 */
function get_slide_promotion_manage_table_data_rows($slides, $controller) {
	$CI = &get_instance();
	$table_data_rows = '';

	foreach ($slides->result() as $slide) {
		$table_data_rows .= get_slide_promotion_data_row($slide, $controller);
	}

	if ($slides -> num_rows() == 0) {
		$table_data_rows .= "<tr><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td></tr>";
	}

	return $table_data_rows;
}

function get_slide_promotion_data_row($slide, $controller) {
	$CI = &get_instance();
	$controller_name = strtolower(get_class($CI));
	$is_active = ($slide -> status == '1') ? 'Enabled' : 'Disabled';
	$table_data_row = '<tr align="center">';
	$table_data_row .= "<td>" . $slide -> slide_promotion_id . "</td>";
	$table_data_row .= '<td>' . character_limiter($slide -> title, 13) . '</td>';
	$table_data_row .= '<td><img src="'. base_url(). F_IMG . $slide -> img_name . '" width="220"/></td>';
	//$table_data_row.='<td>'.character_limiter($person->phone,22).'</td>';
	$table_data_row .= '<td>' . $slide -> created_date . '</td>';
	$table_data_row .= '<td>' . $is_active . '</td>';

	$table_data_row .= '<td><a href="' . base_url() . str_replace('_', '-', $controller_name) . '/update-slide/' . $slide -> slide_promotion_id . '" title="' . $CI -> lang -> line('common_edit') . '"><i class="fa fa-edit fa-fw fa-lg"></i></a> | <a href="' . base_url() . str_replace('_', '-', $controller_name) . '/delete-slide/' . $slide -> slide_promotion_id . '" title="' . $CI -> lang -> line('common_delete') . '" onclick="return confirm(\'Are you sure want to delete?\');"><i class="fa fa-trash-o fa-fw fa-lg"></i></a></td>';

	$table_data_row .= '</tr>';

	return $table_data_row;
}

/*
 Gets the html table to manage feedback.
 */
function get_feedback_manage_table($feedbacks, $controller) {
	$CI = &get_instance();
	$table = '<table class="table table-striped table-bordered table-hover" id="dataTables-example">';

	$headers = array('#', $CI -> lang -> line('header_table_username'), $CI -> lang -> line('header_table_email'), $CI -> lang -> line('header_table_comment'),
	//$CI->lang->line('header_table_phone'),
	$CI -> lang -> line('header_table_created_date'), $CI -> lang -> line('header_table_status'), $CI -> lang -> line('header_table_action'));

	$table .= '<thead><tr>';
	foreach ($headers as $header) {
		$table .= "<th>$header</th>";
	}
	$table .= '</tr></thead><tbody>';
	$table .= get_feedback_manage_table_data_rows($feedbacks, $controller);
	$table .= '</tbody></table>';
	return $table;
}

/*
 Gets the html data rows for the user.
 */
function get_feedback_manage_table_data_rows($feedbacks, $controller) {
	$CI = &get_instance();
	$table_data_rows = '';

	foreach ($feedbacks->result() as $feedback) {
		$table_data_rows .= get_feedback_data_row($feedback, $controller);
	}

	if ($feedbacks -> num_rows() == 0) {
		$table_data_rows .= "<tr class='odd'><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td></tr>";
	}

	return $table_data_rows;
}

function get_feedback_data_row($feedback, $controller) {
	$CI = &get_instance();
	$controller_name = strtolower(get_class($CI));
	$is_active = ($feedback -> status == '1') ? 'Enabled' : 'Disabled';
	$table_data_row = '<tr>';
	$table_data_row .= "<td>" . $feedback -> feedback_id . "</td>";
	$table_data_row .= '<td>' . character_limiter($feedback -> username, 13) . '</td>';
	$table_data_row .= '<td>' . character_limiter($feedback -> email, 25) . '</td>';
	$table_data_row .= '<td>' . character_limiter($feedback -> comment, 125) . '</td>';
	//$table_data_row.='<td>'.character_limiter($person->phone,22).'</td>';
	$table_data_row .= '<td>' . $feedback -> created_date . '</td>';
	$table_data_row .= '<td>' . $is_active . '</td>';

	$table_data_row .= '<td><a href="' . base_url() . str_replace('_', '-', $controller_name) . '/delete-feedback/' . $feedback -> feedback_id . '" title="' . $CI -> lang -> line('common_delete') . '" onclick="return confirm(\'Are you sure want to delete?\');"><i class="fa fa-trash-o fa-fw fa-lg"></i></a></td>';

	$table_data_row .= '</tr>';

	return $table_data_row;
}

/*
 Gets the html table to manage feedback.
 */
function get_posts_manage_table($posts, $controller) {
	$CI = &get_instance();
	$table = '<table class="table table-striped table-bordered table-hover" id="dataTables-example">';

	$headers = array('#', $CI -> lang -> line('header_table_tag_name'), $CI -> lang -> line('header_table_description'), $CI -> lang -> line('header_table_images'),
	//$CI->lang->line('header_table_phone'),
	$CI -> lang -> line('header_table_created_date'), $CI -> lang -> line('header_table_status'), $CI -> lang -> line('header_table_action'));

	$table .= '<thead><tr>';
	foreach ($headers as $header) {
		$table .= "<th>$header</th>";
	}
	$table .= '</tr></thead><tbody>';
	$table .= get_post_manage_table_data_rows($posts, $controller);
	$table .= '</tbody></table>';
	return $table;
}

/*
 Gets the html data rows for the user.
 */
function get_post_manage_table_data_rows($posts, $controller) {
	$CI = &get_instance();
	$table_data_rows = '';

	foreach ($posts->result() as $post) {
		$table_data_rows .= get_post_data_row($post, $controller);
	}

	if ($posts -> num_rows() == 0) {
		$table_data_rows .= "<tr><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td><td>N/A</td></tr>";
	}

	return $table_data_rows;
}

function get_post_data_row($post, $controller) {
	$CI = &get_instance();
	$controller_name = strtolower(get_class($CI));
	$is_active = ($post -> status == '1') ? 'Enabled' : 'Disabled';
	$table_data_row = '<tr>';
	$table_data_row .= "<td>" . $post -> post_id . "</td>";
	$table_data_row .= '<td>' . $post -> use_tag_Id . '</td>';
	$table_data_row .= '<td>' . character_limiter($post -> description, 72) . '</td>';
	$table_data_row .= '<td><img src="'. base_url(). F_IMG . "tags/". $post -> img_name . '" width="180"/></td>';

	$table_data_row .= '<td>' . $post -> created_date . '</td>';
	$table_data_row .= '<td>' . $is_active . '</td>';

	$table_data_row .= '<td><a href="' . base_url() . str_replace('_', '-', $controller_name) . '/update-post/' . $post -> post_id . '" title="' . $CI -> lang -> line('common_edit') . '"><i class="fa fa-edit fa-fw fa-lg"></i></a> | <a href="' . base_url() . str_replace('_', '-', $controller_name) . '/delete-post/' . $post -> post_id . '" title="' . $CI -> lang -> line('common_delete') . '" onclick="return confirm(\'Are you sure want to delete?\');"><i class="fa fa-trash-o fa-fw fa-lg"></i></a></td>';

	$table_data_row .= '</tr>';

	return $table_data_row;
}
?>